package com.system.AttendanceCherkDepartment.dao;

import java.util.ArrayList;
import java.util.Date;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.system.AttendanceCherkDepartment.entity.Attendance;
import com.system.AttendanceCherkDepartment.entity.AttendanceEvent;

@org.springframework.stereotype.Repository
public interface AttendanceRepository extends PagingAndSortingRepository<Attendance,Long>,JpaSpecificationExecutor<Attendance>
{
   	@Modifying 
   	@Query(value="update Attendance atd set atd.attendanceEvent = ?2,atd.time = ?3,atd.totalAbsence = ?4,atd.totalOvertime = ?5,atd.totalLeave = ?6,atd.totalVacation = ?7,atd.totalscore = ?8  where atd.id = ?1") 
   	public int updateAttendance(Long id,
					   			AttendanceEvent attendanceEvent,
					   			Date time,
								Long totalAbsence,
								Long totalOvertime,
								Long totalLeave,
								Long totalVacation,
								Long totalscore
								);
   	
   	@Modifying 
   	@Query(value="delete Attendance atd where atd.id  in (:ids)") 
   	public int deleteAttendances(@Param("ids")Long[] ids);
   	
   	@Query(value="from Attendance attendance where attendance.attendanceEvent like ?1") 
   	public Page<Attendance> findAll(AttendanceEvent attendanceEvent ,Pageable pageable);
   

	@Query(value="from Attendance attendance where attendance.employee.id like ?1") 
	public Page<Attendance> findAll(Long empId,Pageable pageable);
	
	
	
	
	@Query(value="from Attendance attendance") 
	public Page<Attendance> findAll(Pageable pageable);

	@Query(value="from Attendance attendance") 
	public ArrayList<Attendance> findAll();
	
	@Query(value="from Attendance attendance where attendance.employee.id like ?1") 
	public ArrayList<Attendance> findAll(Long empId);
	
}




